using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class InventoryTransactionBLL
    {
        InventoryTransactionDal inventoryTransactionDal = new InventoryTransactionDal();

        public List<InventoryTransactionReturnModel> GetList(InventoryTransactionSearchModel ssm, Pagination page, TokenModel token)
        {
            return inventoryTransactionDal.GetList(ssm, page, token);
        }

        public Guid SaveInventoryTransaction(Inventory_Transaction inventory_Transaction, TokenModel token)
        {
            Guid InventoryTransactionID = inventory_Transaction.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (inventory_Transaction != null)
            {
                //修改
                isSuccess = inventoryTransactionDal.UpdateModel(inventory_Transaction) > 0;

            }
            else
            {
                //新增
                Inventory_Transaction inventoryTransactionInfo = inventoryTransactionDal.AddModel(inventory_Transaction);
                InventoryTransactionID = inventoryTransactionInfo.id;

            }

            return InventoryTransactionID;
        }

        public InventoryTransactionReturnModel GetInventoryTransactionByID(Guid id)
        {
            InventoryTransactionReturnModel inventoryTransactionModel = new InventoryTransactionReturnModel();
            Inventory_Transaction inventoryTransaction = inventoryTransactionDal.FindModel(c => c.id == id);
            inventoryTransactionModel = ClassHelper.ParentCopyToChild<Inventory_Transaction, InventoryTransactionReturnModel>(inventoryTransaction);

            return inventoryTransactionModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return inventoryTransactionDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
